<?php

namespace G4T\Form\Element;

use \G4T\Form\Filter\ImageFilter;

class ImageElement extends \Zend_Form_Element_File implements ElementInterface, TypeInterface
{
    public function init()
    {
        $this->addValidators(array(
            new \Zend_Validate_File_IsImage(),
        ));
    }


    public function setParams(array $params)
    {
        if (!count($params)) {
            return false;
        }
        $defaultDir = \Zend_Registry::get('config')->upload->dir;
        $uploadDir = \Managers\Utils::sanitizePath(dirname(APPLICATION_PATH) . DIRECTORY_SEPARATOR . $defaultDir);
        $this->setDestination($uploadDir);
//        $width = isset($params['width']) ? $params['width'] : null;
//        $height = isset($params['height']) ? $params['height'] : null;
//        $this->addFilter(new ImageFilter($width, $height, $params['dir']));
    }

    /**
     * Текстовое название типа для jqgrid.
     *
     */
    public function getFormElementType()
    {
        return "file";
    }
}
